package com.sunrise.visual.frame.common
{
	public class BarLineUtil
	{
		public var config:Object;
		public var data:Array;
		
		public function BarLineUtil(data:Array,config:Object)
		{
			this.data = data;
			this.config = config;
		}
		private function getXML():XML{
			var xml:XML = <anychart>
						<margin all="0"/>
						<settings>
						<animation enabled="True" />
						</settings>
						<charts>
						<chart plot_type="CategorizedVertical">
						<data_plot_settings default_series_type="Bar">
						<bar_series style="Silver" group_padding={this.config.groupPadding || "1"} point_padding={this.config.pointPadding || '0.2'}>
						<bar_style enabled="True">
						<states>
		 	              <selected_normal color={this.config.selectedColor || "%Color"}/>
		 	            </states>
		 	            </bar_style>
						<tooltip_settings enabled="True">
<font family="Microsoft Yahei" bold="false" size="12"/>
						<format>{this.config.labelFormat || "{%SeriesName}\n{%Name}{numDecimals:0}号:{%YValue}{numDecimals:0}(个)"}</format>
						</tooltip_settings>
						</bar_series>
						<line_series>
						<marker_settings>
						<marker type={this.config.makerType || "None"} />
						<states>
						<hover>
						<marker type="Diamond" />
						</hover>
						</states>
						</marker_settings>
						<tooltip_settings enabled="True">
<font family="Microsoft Yahei" bold="false" size="12"/>
						<format>{this.config.tooltipFormat || "{%SeriesName}\n{%Name}{numDecimals:0}号:{%YValue}{numDecimals:2}(%)"}</format>
						</tooltip_settings>
							<label_settings enabled={this.config.lineLabelEnabled||'false'}>
<font family="Microsoft Yahei" bold="false" size="11" color="white"/>
								<format>{this.config.lineLabelFormat || "{%SeriesName}\n{%Name}{numDecimals:0}号:{%YValue}{numDecimals:0}(个)"}</format>
							</label_settings>
						</line_series>
						</data_plot_settings>
						<chart_settings>
						<chart_background enabled="false">
						      <inside_margin left="0" top="0" right="0" bottom="0"/>
						</chart_background>
						<data_plot_background enabled="false" />
						<controls>
							<label position="Fixed" anchor="LeftTop" inside_dataplot="false" enabled={this.config.controlsLabel1Enabled || "false"}>
<font family="Microsoft Yahei" bold="False" size="12" color="white" />
								<text>{this.config.controlsLabel1Text || ""}</text>
							</label>
							<label position="Float" anchor="RightTop" inside_dataplot="false" horizontal_padding={this.config.controlsLabel2Margin || 1} enabled={this.config.controlsLabel2Enabled || "false"}>
<font family="Microsoft Yahei" bold="False" size="12" color="white" />
								<text>{this.config.controlsLabel2Text || ""}</text>
							</label>
						</controls>
						<title enabled={this.config.titleEnabled || "false"}>
							<text>{this.config.title || ''}</text>
<font family="Microsoft Yahei" bold="True" size="16" color="white" />
						</title>
						<axes>
						<x_axis>
						<line color="white"/>
						<major_tickmark color="white"/>
						<title enabled="false"/>
						<labels>
<font family="Microsoft Yahei" bold="false" size={this.config.xaxisFontSize||10} color="white"/>
						</labels>
						<major_grid enabled="false"/>
						<minor_grid enabled="false"/>
						</x_axis>
						<y_axis>
<scale mode="Normal" maximum_offset={this.config.maximumOffset||"0.1"}/>
						<line color="white"/>
						<major_tickmark color="white"/>
						<title enabled="false"/>
						<labels>
						<format>{"{%Value}{numDecimals:"}{this.config.format_Y1data || "0"}{"}"}</format>
<font family="Microsoft Yahei" bold="false" size="10" color="white"/>
						</labels>
						<major_grid enabled="false"/>
						<minor_grid enabled="false"/>
						</y_axis>
						<extra>
						<y_axis name="y_axis2" position="Opposite">
<scale mode="Normal" maximum_offset={this.config.maximumOffset||"0.1"}/>
						<line color="white"/>
						<major_tickmark color="white"/>
						<title enabled="false"/>
						<labels>
<font family="Microsoft Yahei" bold="false" size="12" color="white"/>
						<format>{this.config.Y2_format || "{%Value}{numDecimals:2}"}</format>
						</labels>
						<major_grid enabled="false"/>
						<minor_grid enabled="false"/>
						</y_axis>
						</extra>
						</axes>
						<legend enabled="true" ignore_auto_item="true" align="center" rows_padding="2" position={this.config.legendPosition||"bottom"}>
<font family="Microsoft Yahei" bold="False" size="12" color="white">
						</font>
						<background enabled="false"/>
						<title enabled="false"/>
						<items>
						<item source="series" />
						</items>
						</legend>
						</chart_settings>
						<data>
						</data>
						</chart>
						</charts>
						</anychart>;
			return xml;
		}
		
		public function parseXML():XML {
			var wdbm:String=this.config.wdbm;
			var zbbm:Array=this.config.zbbm;
			var zbmc:Array=this.config.zbmc;
			var paramsColumns:Array = this.config.paramsColumns || [];
			var xmlStr:String="";
			var xml:XML = getXML();
			//xml.charts[0].chart[0].data[0]="";
			var seriesColor:Array = this.config.seriesColor || ['#00DFF3','#95A600'];
			for(var i:int=0;i<zbbm.length;i++){
				xmlStr='<series name="' + zbmc[i] + '" type="' + (this.config.chartType[i] || 'Bar') + '" y_axis="' + (this.config.y_axis[i] || 'y_axis') + '" color="'+seriesColor[i]+'">'; 
				for(var j : int=0; j < this.data.length; j++){
					xmlStr += '<point name="' + this.data[j][wdbm] + '" y="' + this.data[j][zbbm[i]] + '">';
					xmlStr += '<attributes>';
					for(var k:int = 0; k < paramsColumns.length; k++) {
						xmlStr += '<attribute name="' + paramsColumns[k] + '">' + this.data[j][paramsColumns[k]] + '</attribute>';
					}
					xmlStr += '</attributes></point>';
				}
				xmlStr += '</series>';
				xml.charts[0].chart[0].data[0].appendChild(new XML(xmlStr));
			}
			return xml;
		}
	}
}